package com.chenfan.process.controller;

import com.chenfan.ccp.common.result.R;
import com.chenfan.process.biz.ApprovalTransferBiz;
import com.chenfan.process.biz.DataInitializerBiz;
import com.chenfan.process.entity.dto.RefreshDataDTO;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.concurrent.ExecutionException;

/**
 * @author K
 * @date 2022/6/27 11:15 AM
 */
@RestController
@RequestMapping("/data/init")
public class DataInitializerController {

    @Autowired
    private DataInitializerBiz dataInitializerBiz;

    @Autowired
    private ApprovalTransferBiz approvalTransferBiz;

    @ApiOperation("数据初始化")
    @GetMapping("/snapshot")
    public R<Void> initData(@RequestBody List<Long> approvalTemplateIdList) throws ExecutionException, InterruptedException {
        approvalTransferBiz.initData(approvalTemplateIdList);
        return R.ok();
    }

    @ApiOperation("数据初始化")
    @GetMapping("/snapshot/refresh")
    public R<Void> incrementData(@RequestBody RefreshDataDTO refreshData) throws InterruptedException, ExecutionException {
        approvalTransferBiz.incrementData(refreshData);
        return R.ok();
    }

    @ApiOperation("增加组概念")
    @PutMapping("/group")
    public R<Void> groupDataInit(@RequestBody List<Long> approvalTemplateIdList) {
        dataInitializerBiz.groupDataInit(approvalTemplateIdList);
        return R.ok();
    }

    @ApiOperation("关联关系增加组概念")
    @PutMapping("related/group")
    public R<Void> relatedGroupInit(@RequestBody List<Long> approvalTemplateIdList) {
        dataInitializerBiz.relatedGroupInit(approvalTemplateIdList);
        return R.ok();
    }

    @ApiOperation("模板快照内容刷新")
    @PutMapping("/template/snapshot")
    public R<Void> refreshTemplateSnapshot(@RequestBody List<Long> approvalTemplateIdList) {
        dataInitializerBiz.refreshTemplateSnapshot(approvalTemplateIdList);
        return R.ok();
    }

    @ApiOperation("或签刷新")
    @PutMapping("/template/snapshot/refresh")
    public R<Void> splitTemplateSnapshot(@RequestBody List<Long> approvalTemplateIdList) {
        dataInitializerBiz.splitTemplateSnapshot(approvalTemplateIdList);
        return R.ok();
    }
}
